import httpUtil from "../utils/httpUtil"
import messageUtil from "../utils/messageUtil"
import logApi from "./logApi"
import paramApi from "./paramApi"
import userApi from "./userApi"
import zfbMiniPayApi from "./zfbMiniPayApi"
import zfbUrlUtil from "@/utils/zfbUrlUtil.js"

/**
 * 
 * @see 
 */
const submitOrder = (mobile, proCode, successCallBack, errorCallBack) => {
	let params = {
		a: httpUtil.getA(),
		mobile,
		proType: 2,
	}
	if (proCode) {
		params.proCode = proCode
	}
	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (userApi.getUserId()) {
		params.openid = userApi.getUserId()
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/souhu/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
		// zfbMiniPayApi.zhouqiPayHandler(res.data.str, successCallBack, zhouqiError => {
		// 	if (zhouqiError.errorMessage) {
		// 		messageUtil.showFail(zhouqiError.errorMessage)
		// 	}
		// 	if (errorCallBack) {
		// 		errorCallBack(zhouqiError)
		// 	}
		// })
		my.ap.openURL({
			url: res.data.payUrl, // 请将 url 替换为有效的页面地址
			success: (res) => {
				console.log('openURL success', res)
			},
			fail: (err) => {
				console.log('openURL success', err)
			}
		});

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
// proType  1=29.9 2=0.01 3=免费
const submitOrder1 = (mobile, proCode, successCallBack, errorCallBack) => {
	let params = {
		a: httpUtil.getA(),
		mobile,
		proType: 1,
	}
	if (proCode) {
		params.proCode = proCode
	}
	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (userApi.getUserId()) {
		params.openid = userApi.getUserId()
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/souhu/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
	
		my.ap.openURL({
			url: res.data.payUrl, // 请将 url 替换为有效的页面地址
			success: (res) => {
				console.log('openURL success', res)
			},
			fail: (err) => {
				console.log('openURL success', err)
			}
		});

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
const submitOrder2 = (mobile, proCode, successCallBack, errorCallBack) => {
	let params = {
		a: httpUtil.getA(),
		mobile,
		proType: 3,
	}
	if(uni.getStorageSync('uuid')){
		params.uuid = uni.getStorageSync('uuid')
		
	}
	if (proCode) {
		params.proCode = proCode
	}
	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (userApi.getUserId()) {
		params.openid = userApi.getUserId()
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/souhu/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
	
		my.ap.openURL({
			url: res.data.payUrl, // 请将 url 替换为有效的页面地址
			success: (res) => {
				console.log('openURL success', res)
			},
			fail: (err) => {
				console.log('openURL success', err)
			}
		});

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
const gudong = (mobile, proCode, successCallBack, errorCallBack) => {
	let params = {
		a: httpUtil.getA(),
		mobile,
	
	}
	if (proCode) {
		params.proCode = proCode
	}
	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (userApi.getUserId()) {
		params.openid = userApi.getUserId()
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/shengxin/gd_subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
	
		my.ap.openURL({
			url: res.data.payUrl, // 请将 url 替换为有效的页面地址
			success: (res) => {
				console.log('openURL success', res)
			},
			fail: (err) => {
				console.log('openURL success', err)
			}
		});

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
export default {
	submitOrder,
	submitOrder1,
	submitOrder2,
	gudong
}